/**
 * Created by hehe on 2015/7/21.
 */
var Parser = require('parse-xl'),
    constants = require('commom').constants;

function BaseParser(option) {
    this.filePath = option.filePath;
}

BaseParser.prototype.verifyData = function (arr) {
    for (var i in arr) {
        if (arr[i] && arr[i] != "undefined") {
            return true;
        }
    }
    return false;
}

BaseParser.prototype.parseExcel = function () {
    var parser = new Parser(constants.file.basePath + this.filePath);
    var data = parser.tocsv('MMLineFeed', 'MMNewLine');
    var DDArry = new Array(), firstSheet = true;

    for (var sheetName in data) {
        if (firstSheet) {
            var dataArray = data[sheetName].split('MMNewLine');
            for (var i in dataArray) {
                var arr = dataArray[i].split('MMLineFeed')
                if (this.verifyData(arr)) {
                    DDArry.push(arr);
                }
            }
            firstSheet = false;
        }
    }
    return DDArry;
}

BaseParser.prototype.parseDate = function(time){
    return new Date(time);
}
module.exports.BaseParser = BaseParser;
